﻿using Future.Common.Models;
using Future.IDAL;
using Future.Model.DtoModel;
using Future.Model.SysModel;
using System.Text;

namespace Future.DAL
{
    /// <summary>
    /// 描述：字典类型数据访问类
    /// 创建人： yangkai
    /// 创建时间：2022/11/21 18:34:43
    /// </summary>
    public class DictTypeDAL : BaseDAL<DictTypeModel>, IDictTypeDAL
    {
        public Task<PageModel<DictTypeModel>> SelctPageList(DictTypeQueryDto dictTypeQueryDto, PageParModel page)
        {
            string sql = @"SELECT [Id]
                              ,[DictName]
                              ,[DictType]
                              ,[Status]
                              ,[CreateBy]
                              ,[CreateTime]
                              ,[UpdateBy]
                              ,[UpdateTime]
                              ,[Remark]
                          FROM [Future].[dbo].[Sys_DictType]
                          WHERE 1 = 1";

            StringBuilder stringBuilder = new();
            Dictionary<string, object> parameters = new();
            if (!string.IsNullOrEmpty(dictTypeQueryDto.DictName))
            {
                stringBuilder.Append(" and DictName like '%'+@DictName+'%'");
                parameters.Add("DictName", dictTypeQueryDto.DictName);
            }

            if (!string.IsNullOrEmpty(dictTypeQueryDto.DictType))
            {
                stringBuilder.Append(" and DictType like '%'+@DictType+'%'");
                parameters.Add("DictType", dictTypeQueryDto.DictType);
            }

            if (dictTypeQueryDto.Status.HasValue)
            {
                stringBuilder.Append(" and Status = @Status");
                parameters.Add("Status", dictTypeQueryDto.Status.Value);
            }

            if (dictTypeQueryDto.StartTime.HasValue)
            {
                stringBuilder.Append(" and CreateTime > @StartTime");
                parameters.Add("StartTime", dictTypeQueryDto.StartTime.Value);
            }

            if (dictTypeQueryDto.EndTime.HasValue)
            {
                stringBuilder.Append(" and CreateTime <= @EndTime");
                parameters.Add("EndTime", dictTypeQueryDto.EndTime.Value);
            }

            sql += stringBuilder.ToString();
            return PageListAsync(sql, parameters, page);
        }
    }
}
